Function: semantic-grammar-parsetable-builder-bovine-grammar-mode
semantic-grammar-parsetable-builder-bovine-grammar-mode is a
byte-compiled function defined in grammar.el.gz.
Signature
(semantic-grammar-parsetable-builder-bovine-grammar-mode)
Documentation
Return the parser table expression as a string value.
The format of a bovine parser table is:
( ( NONTERMINAL-SYMBOL1 MATCH-LIST1 )
( NONTERMINAL-SYMBOL2 MATCH-LIST2 )
...
( NONTERMINAL-SYMBOLn MATCH-LISTn )
Where each NONTERMINAL-SYMBOL is an artificial symbol which can appear
in any child state. As a starting place, one of the NONTERMINAL-SYMBOLS
must be bovine-toplevel.
A MATCH-LIST is a list of possible matches of the form:
( STATE-LIST1
STATE-LIST2
...
STATE-LISTN )
where STATE-LIST is of the form:
( TYPE1 [ "VALUE1" ] TYPE2 [ "VALUE2" ] ... LAMBDA )
where TYPE is one of the returned types of the token stream. VALUE is a value, or range of values to match against. For example, a SYMBOL might need to match "foo". Some TYPES will not have matching criteria.
LAMBDA is a lambda expression which is evalled with the text of the type when it is found. It is passed the list of all buffer text elements found since the last lambda expression. It should return a semantic element (see below.)
For consistency between languages, try to use common return values
from your parser. Please reference the chapter "Writing Parsers" in
the "Language Support Developer's Guide -" in the semantic texinfo
manual.
Override semantic-grammar-parsetable-builder in bovine-grammar-mode
buffers.
Source Code
;; Defined in /usr/src/emacs/lisp/cedet/semantic/bovine/grammar.el.gz
(define-mode-local-override semantic-grammar-parsetable-builder
bovine-grammar-mode ()
"Return the parser table expression as a string value.
The format of a bovine parser table is:
( ( NONTERMINAL-SYMBOL1 MATCH-LIST1 )
( NONTERMINAL-SYMBOL2 MATCH-LIST2 )
...
( NONTERMINAL-SYMBOLn MATCH-LISTn )
Where each NONTERMINAL-SYMBOL is an artificial symbol which can appear
in any child state. As a starting place, one of the NONTERMINAL-SYMBOLS
must be `bovine-toplevel'.
A MATCH-LIST is a list of possible matches of the form:
( STATE-LIST1
STATE-LIST2
...
STATE-LISTN )
where STATE-LIST is of the form:
( TYPE1 [ \"VALUE1\" ] TYPE2 [ \"VALUE2\" ] ... LAMBDA )
where TYPE is one of the returned types of the token stream.
VALUE is a value, or range of values to match against. For
example, a SYMBOL might need to match \"foo\". Some TYPES will not
have matching criteria.
LAMBDA is a lambda expression which is evalled with the text of the
type when it is found. It is passed the list of all buffer text
elements found since the last lambda expression. It should return a
semantic element (see below.)
For consistency between languages, try to use common return values
from your parser. Please reference the chapter \"Writing Parsers\" in
the \"Language Support Developer's Guide -\" in the semantic texinfo
manual."
(let* ((start (semantic-grammar-start))
(scopestart (semantic-grammar-scopestart))
(quotemode (semantic-grammar-quotemode))
(tags (semantic-find-tags-by-class
'token (current-buffer)))
(nterms (semantic-find-tags-by-class
'nonterminal (current-buffer)))
;; Setup the cache of macro definitions.
(bovine--grammar-macros (semantic-grammar-macros))
nterm rules items item actn prec tag type regex)
;; Check some trivial things
(cond
((null nterms)
(error "Bad input grammar"))
(start
(if (cdr start)
(message "Extra start symbols %S ignored" (cdr start)))
(setq start (symbol-name (car start)))
(unless (semantic-find-first-tag-by-name start nterms)
(error "start symbol `%s' has no rule" start)))
(t
;; Default to the first grammar rule.
(setq start (semantic-tag-name (car nterms)))))
(when scopestart
(setq scopestart (symbol-name scopestart))
(unless (semantic-find-first-tag-by-name scopestart nterms)
(error "scopestart symbol `%s' has no rule" scopestart)))
;; Generate the grammar Lisp form.
(with-temp-buffer
(erase-buffer)
(insert "`(")
;; Insert the start/scopestart rules
(insert "\n(bovine-toplevel \n("
start
")\n) ;; end bovine-toplevel\n")
(when scopestart
(insert "\n(bovine-inner-scope \n("
scopestart
")\n) ;; end bovine-inner-scope\n"))
;; Process each nonterminal
(while nterms
(setq nterm (car nterms)
;; We can't use the override form because the current buffer
;; is not the originator of the tag.
rules (semantic-tag-components-semantic-grammar-mode nterm)
nterm (semantic-tag-name nterm)
nterms (cdr nterms))
(when (member nterm '("bovine-toplevel" "bovine-inner-scope"))
(error "`%s' is a reserved internal name" nterm))
(insert "\n(" nterm)
;; Process each rule
(while rules
(setq items (semantic-tag-get-attribute (car rules) :value)
prec (semantic-tag-get-attribute (car rules) :prec)
actn (semantic-tag-get-attribute (car rules) :expr)
rules (cdr rules))
;; Process each item
(insert "\n(")
(if (null items)
;; EMPTY rule
(insert ";;EMPTY" (if actn "" "\n"))
;; Expand items
(while items
(setq item (car items)
items (cdr items))
(if (consp item) ;; mid-rule action
(message "Mid-rule action %S ignored" item)
(or (char-equal (char-before) ?\()
(insert "\n"))
(cond
((member item '("bovine-toplevel" "bovine-inner-scope"))
(error "`%s' is a reserved internal name" item))
;; Replace ITEM by its %token definition.
;; If a '%token TYPE ITEM [REGEX]' definition exists
;; in the grammar, ITEM is replaced by TYPE [REGEX].
((setq tag (semantic-find-first-tag-by-name
item tags)
type (semantic-tag-get-attribute tag :type))
(insert type)
(if (setq regex (semantic-tag-get-attribute tag :value))
(insert (format "\n%S" regex))))
;; Don't change ITEM
(t
(insert (semantic-grammar-item-text item)))
))))
(if prec
(message "%%prec %S ignored" prec))
(if actn
(bovine-grammar-expand-action actn quotemode))
(insert ")"))
(insert "\n) ;; end " nterm "\n"))
(insert ")\n")
(buffer-string))))