New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scala grammar #1220

Merged
merged 1 commit into from Sep 9, 2018

Conversation

Projects
None yet
3 participants
@d10xa
Copy link
Contributor

d10xa commented Sep 9, 2018

I did not see file contributors.txt in repository and add copyright to grammar file. Is it ok?

That PR fix lexer. It looks working now for hello world.

Tokens for example2.txt :

1) 'package': package
2) Id: foo
3) '.': .
4) Id: bar
5) 'import': import
6) Id: scala
7) '.': .
8) Id: concurrent
9) '.': .
10) Id: ExecutionContext
11) '.': .
12) Id: Implicits
13) '.': .
14) '_': _
15) 'object': object
16) Id: HelloWorld
17) '{': {
18) 'def': def
19) Id: main
20) '(': (
21) Id: args
22) ':': :
23) Id: Array
24) '[': [
25) Id: `String`
26) ']': ]
27) ')': )
28) ':': :
29) Id: Unit
30) '=': =
31) '{': {
32) Id: println
33) '(': (
34) StringLiteral: "Hello, world!"
35) ')': )
36) '}': }
37) '}': }

ParseTreeListener with println's output:

enterEveryRule, compilationUnit []
packagefoo.barobjectHelloWorld
visitTerminal, package
enterEveryRule, qualId [1411]
foo.bar
visitTerminal, foo
visitTerminal, .
visitTerminal, bar
exitEveryRule, [1411]
enterEveryRule, topStatSeq [1420]
objectHelloWorld
enterEveryRule, topStat [1373 1420]
objectHelloWorld
enterEveryRule, tmplDef [1393 1373 1420]
objectHelloWorld
visitTerminal, object
enterEveryRule, objectDef [1237 1393 1373 1420]
HelloWorld
visitTerminal, HelloWorld
enterEveryRule, classTemplateOpt [1265 1237 1393 1373 1420]

exitEveryRule, [1265 1237 1393 1373 1420]
exitEveryRule, [1237 1393 1373 1420]
exitEveryRule, [1393 1373 1420]
exitEveryRule, [1373 1420]
exitEveryRule, [1420]
exitEveryRule, []

The parser still has problems. If uncomment import statement the output will be following:

enterEveryRule, compilationUnit []
packagefoo.barimportscala.concurrent.ExecutionContext
visitTerminal, package
enterEveryRule, qualId [1411]
foo.bar
visitTerminal, foo
visitTerminal, .
visitTerminal, bar
exitEveryRule, [1411]
enterEveryRule, topStatSeq [1420]
importscala.concurrent.ExecutionContext
enterEveryRule, topStat [1373 1420]
importscala.concurrent.ExecutionContext
enterEveryRule, import_ [1394 1373 1420]
importscala.concurrent.ExecutionContext
visitTerminal, import
enterEveryRule, importExpr [1079 1394 1373 1420]
scala.concurrent.ExecutionContext
enterEveryRule, stableId [1087 1079 1394 1373 1420]
scala.concurrent
visitTerminal, scala
visitTerminal, .
visitTerminal, concurrent
exitEveryRule, [1087 1079 1394 1373 1420]
visitTerminal, .
visitTerminal, ExecutionContext
exitEveryRule, [1079 1394 1373 1420]
exitEveryRule, [1394 1373 1420]
exitEveryRule, [1373 1420]
exitEveryRule, [1420]
exitEveryRule, []

@d10xa d10xa force-pushed the d10xa:517-fix-scala-grammar branch from 3e5e731 to 43a1071 Sep 9, 2018

@teverett

This comment has been minimized.

Copy link
Member

teverett commented Sep 9, 2018

@d10xa thanks

@teverett teverett merged commit fa25a7e into antlr:master Sep 9, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@KvanTTT KvanTTT added the scala label Sep 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment