Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
menhir
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
12
Issues
12
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
POTTIER Francois
menhir
Commits
5b199ff7
Commit
5b199ff7
authored
Mar 21, 2017
by
POTTIER Francois
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lexer: emit the tokens ATTRIBUTE, GRAMMARATTRIBUTE, PERCENTATTRIBUTE.
parent
54fbd462
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
0 deletions
+67
-0
src/fancy-parser.mly
src/fancy-parser.mly
+2
-0
src/lexer.mll
src/lexer.mll
+52
-0
src/syntax.mli
src/syntax.mli
+11
-0
src/yacc-parser.mly
src/yacc-parser.mly
+2
-0
No files found.
src/fancy-parser.mly
View file @
5b199ff7
...
...
@@ -25,6 +25,8 @@ open Positions
%
token
<
Stretch
.
ocamltype
>
OCAMLTYPE
%
token
<
Stretch
.
t
Lazy
.
t
>
PERCENTPERCENT
%
token
<
Syntax
.
identifier
option
array
->
Action
.
t
>
ACTION
%
token
<
Syntax
.
attribute
>
ATTRIBUTE
GRAMMARATTRIBUTE
%
token
PERCENTATTRIBUTE
/*
-------------------------------------------------------------------------
*/
/*
Start
symbol
.
*/
...
...
src/lexer.mll
View file @
5b199ff7
...
...
@@ -333,6 +333,8 @@ let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222']
let
identchar
=
[
'
A'
-
'
Z'
'
a'
-
'
z'
'
_'
'\192'
-
'\214'
'\216'
-
'\246'
'\248'
-
'\255'
'
0
'
-
'
9
'
]
(* '\'' forbidden *)
let
attributechar
=
identchar
|
'.'
let
poskeyword
=
'
$
'
((
"symbolstart"
|
"start"
|
"end"
)
as
where
)
...
...
@@ -370,6 +372,8 @@ rule main = parse
{
PARAMETER
}
|
"%inline"
{
INLINE
}
|
"%attribute"
{
PERCENTATTRIBUTE
}
|
"%on_error_reduce"
{
ON_ERROR_REDUCE
}
|
"%%"
...
...
@@ -441,6 +445,20 @@ rule main = parse
Action
.
from_stretch
stretch
)
)
}
|
(
'
%
'
?
as
percent
)
"[@"
(
attributechar
+
as
id
)
whitespace
*
{
let
openingpos
=
lexeme_start_p
lexbuf
in
let
stretchpos
=
lexeme_end_p
lexbuf
in
let
closingpos
=
attribute
openingpos
lexbuf
in
let
pos
=
Positions
.
lex_join
openingpos
closingpos
in
let
attr
=
mk_stretch
stretchpos
closingpos
false
[]
in
Printf
.
fprintf
stderr
"Coucou
\n
%!"
;
if
percent
=
""
then
(* No [%] sign: this is a normal attribute. *)
ATTRIBUTE
(
Positions
.
with_pos
pos
id
,
attr
)
else
(* A [%] sign is present: this is a grammar-wide attribute. *)
GRAMMARATTRIBUTE
(
Positions
.
with_pos
pos
id
,
attr
)
}
|
eof
{
EOF
}
|
_
...
...
@@ -575,6 +593,40 @@ and parentheses openingpos monsters = parse
(* ------------------------------------------------------------------------ *)
(* Collect an attribute payload, which is terminated by a closing square
bracket. Nested square brackets must be properly counted. Nested curly
brackets and nested parentheses are also kept track of, so as to better
report errors when they are not balanced. *)
and attribute openingpos = parse
| '['
{ let _ = attribute (lexeme_start_p lexbuf) lexbuf in
attribute openingpos lexbuf }
| ']'
{ lexeme_start_p lexbuf }
| '{'
{ let _, _ = action false (lexeme_start_p lexbuf) [] lexbuf in
attribute openingpos lexbuf }
| '('
{ let _, _ = parentheses (lexeme_start_p lexbuf) [] lexbuf in
attribute openingpos lexbuf }
| '"'
{ string (lexeme_start_p lexbuf) lexbuf; attribute openingpos lexbuf }
| "'"
{ char lexbuf; attribute openingpos lexbuf }
| "(*"
{ ocamlcomment (lexeme_start_p lexbuf) lexbuf; attribute openingpos lexbuf }
| newline
{ new_line lexbuf; attribute openingpos lexbuf }
| '}'
| ')'
| eof
{ error1 openingpos "unbalanced opening bracket." }
| _
{ attribute openingpos lexbuf }
(* ------------------------------------------------------------------------ *)
(* Skip O'Caml comments. Comments can be nested and can contain
strings or characters, which must be correctly analyzed. (A string
could contain begin-of-comment or end-of-comment sequences, which
...
...
src/syntax.mli
View file @
5b199ff7
...
...
@@ -43,6 +43,17 @@ type action =
(* ------------------------------------------------------------------------ *)
(* An attribute consists of an attribute name and an attribute payload. The
payload is an uninterpreted stretch of source text. *)
type
attribute
=
string
Positions
.
located
*
Stretch
.
t
type
attributes
=
attribute
list
(* ------------------------------------------------------------------------ *)
(* Information about tokens. (Only after joining.) *)
type
token_associativity
=
...
...
src/yacc-parser.mly
View file @
5b199ff7
...
...
@@ -19,6 +19,8 @@ open Positions
%
token
<
Stretch
.
ocamltype
>
OCAMLTYPE
%
token
<
Stretch
.
t
Lazy
.
t
>
PERCENTPERCENT
%
token
<
Syntax
.
identifier
option
array
->
Syntax
.
action
>
ACTION
%
token
<
Syntax
.
attribute
>
ATTRIBUTE
GRAMMARATTRIBUTE
%
token
PERCENTATTRIBUTE
%
start
grammar
%
type
<
Syntax
.
partial_grammar
>
grammar
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment