Skip to content

Commit 0201b61

Browse files
committed
[Core] Synchronize lexer output with C++ implementation
1 parent 75ff557 commit 0201b61

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ Semantic Authoring Markdown
55

66
Implementation of a SAM toolset in Java using an ANTLRv4 Grammar.
77

8+
For a C++ implementation please see [SamX-C++](https://github.com/0x8000-0000/samx-cpp)
9+
10+
811
Please see [SAM Documentation](https://mbakeranalecta.github.io/sam/) for
912
an overview and scope of SAM. Please refer to
1013
https://github.com/mbakeranalecta/sam for the original implementation.
1114

15+
1216
Dependencies
1317
------------
1418

@@ -82,6 +86,7 @@ License for SAM
8286
[Original SAM code is available](https://github.com/mbakeranalecta/sam/blob/master/license.txt)
8387
under Apache 2.0 license or Eclipse Public License v1.0.
8488

89+
8590
License for SAMx
8691
----------------
8792

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group 'net.signbit.samx'
10-
version '0.4.7'
10+
version '0.4.8'
1111

1212
sourceCompatibility = 1.8
1313

@@ -53,6 +53,7 @@ task createAllStartScripts() {
5353
}
5454

5555
def scripts = ['tokenize' : 'net.signbit.samx.Tokenize',
56+
'raw_tokens' : 'net.signbit.samx.RawTokens',
5657
'to_xml' : 'net.signbit.samx.ConvertToXml',
5758
'to_html' : 'net.signbit.samx.ConvertToHtml',
5859
'pretty_print' : 'net.signbit.samx.PrettyPrint',

src/main/antlr/SamXLexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ tokens { INDENT, DEDENT, END, INVALID, BOL }
152152
private void addCodeIndent(int indentLevel)
153153
{
154154
java.lang.StringBuilder builder = new java.lang.StringBuilder(indentLevel + 1);
155-
for (int ii = 0; ii < indentLevel; ++ii)
155+
for (int ii = 0; ii <= indentLevel; ++ii)
156156
{
157157
builder.append(' ');
158158
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright 2020 Florin Iucha
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package net.signbit.samx;
18+
19+
import java.io.IOException;
20+
21+
import org.antlr.v4.runtime.CharStream;
22+
import org.antlr.v4.runtime.CharStreams;
23+
import org.antlr.v4.runtime.CommonTokenStream;
24+
import org.antlr.v4.runtime.Token;
25+
26+
import net.signbit.samx.parser.SamXLexer;
27+
import net.signbit.samx.parser.SamXParser;
28+
29+
public final class RawTokens
30+
{
31+
public static void main(String[] args)
32+
{
33+
if (args.length < 1)
34+
{
35+
System.err.println("No arguments provided");
36+
return;
37+
}
38+
39+
try
40+
{
41+
CharStream input = CharStreams.fromFileName(args[0]);
42+
43+
SamXLexer lexer = new SamXLexer(input);
44+
45+
CommonTokenStream tokens = new CommonTokenStream(lexer);
46+
47+
tokens.fill();
48+
49+
for (Token tok : tokens.getTokens())
50+
{
51+
System.out.println(tok);
52+
}
53+
}
54+
catch (IOException ioe)
55+
{
56+
System.err.println("Caught i/o exception: " + ioe.getMessage());
57+
}
58+
catch (Exception ee)
59+
{
60+
System.err.println("Caught exception: " + ee.getMessage());
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)