meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
convention_over_configuration [2020/02/12 19:24] – created revuskyconvention_over_configuration [2020/04/25 18:15] – external edit 127.0.0.1
Line 18: Line 18:
 However, for people who never used legacy JavaCC, this would have no bearing and we assume that most people would prefer the shorter name ''FooLexer''. However, for people who never used legacy JavaCC, this would have no bearing and we assume that most people would prefer the shorter name ''FooLexer''.
  
-The generated constants interface will be called ''FooConstants''. This can be overridden by using the CONSTANTS_CLASS option. To keep the name that would be generated in JavaCC, FooParserConstants, you can specify ''CONSTANTS_CLASS="FooParserConstants"'' in your options. But again, little reason to change this. +The generated constants interface will be called ''FooConstants''. This can be overridden by using the CONSTANTS_CLASS option. To keep the name that would be generated in JavaCC, FooParserConstants, you can specify ''CONSTANTS_CLASS="FooParserConstants"'' in your options. But again, there is little reason to change this. 
  
-If not specified otherwise, all classes will be generated with no package (the default package) in the same directory as the FreeCC grammar file. However, in this instance, it is strongly recommended that, at least for non-trivial projects, you should specify a package using the PARSER_PACKAGE option and also a base source directory using the new ''BASE_SRC_DIR'' option. As a concrete example, let us suppose the Foo project keeps the ''Foo.javacc'' file in the directory ''src/parser'' (relative to the project root) and that (as per very common conventions) your java source code is located in the src/java directory. In that case, you would specify BASE_SRC_DIR="../java" in your grammar file. (Obviously using a relative directory for BASE_SRC_DIR will tend to be more robust than an absolute directory.) Now, supposing that you want your Foo language parser code to reside in the package org.foolang.parser you would have the option ''PARSER_PACKAGE="org.foolang.parser:'' in your grammar file. Thus, the source files would be generated in the directory ''src/java/org/foolang/parser''.+If not specified otherwise, all classes will be generated with no package (the default package) in the same directory as the grammar file. However, in this instance, it is strongly recommended that, at least for non-trivial projects, you should specify a package using the PARSER_PACKAGE option and also a base source directory using the new ''BASE_SRC_DIR'' option. As a concrete example, let us suppose the Foo project keeps the ''Foo.javacc'' file in the directory ''src/parser'' (relative to the project root) and that (as per very common conventions) your java source code is located in the src/java directory. In that case, you would specify BASE_SRC_DIR="../java" in your grammar file. (Obviously using a relative directory for BASE_SRC_DIR will tend to be more robust than an absolute directory.) Now, supposing that you want your Foo language parser code to reside in the package org.foolang.parser you would have the option ''PARSER_PACKAGE="org.foolang.parser:'' in your grammar file. Thus, the source files would be generated in the directory ''src/java/org/foolang/parser''.
  
 ===== Putting your AST Nodes in their own package ===== ===== Putting your AST Nodes in their own package =====
Line 26: Line 26:
 If you have tree building enabled, you may wish to specify a separate directory in which to put the classes used to represent the nodes in your parse tree. You can do this using the NODE_PACKAGE option. Like PARSER_PACKAGE, this option is taken to be relative to the base source directory specified via BASE_SRC_DIR. If you have tree building enabled, you may wish to specify a separate directory in which to put the classes used to represent the nodes in your parse tree. You can do this using the NODE_PACKAGE option. Like PARSER_PACKAGE, this option is taken to be relative to the base source directory specified via BASE_SRC_DIR.
  
-Note that the default name for the base node class has been changed from SimpleNode to BaseNode. If you wish to use a different name, for example, to keep using SimpleNode, you can use the BASE_NODE_CLASS option to specify a different name, i.e. BASE_NODE_CLASS="SimpleNode". Again, the main reason to do this would be if one is moving from using JavaCC to FreeCC. If you never used JavaCC previously, then there is little reason to change the name. +Note that the default name for the base node class has been changed from SimpleNode to BaseNode. If you wish to use a different name, for example, to keep using SimpleNode, you can use the BASE_NODE_CLASS option to specify a different name, i.e. BASE_NODE_CLASS="SimpleNode". Again, the main reason to do this would be if one is migrating from the legacy tool. If you never used JavaCC previously, then there is little reason to change the name. 
  
 +Because of the above changes, there are various configuration options in legacy JavaCC that are no longer meaningful in JavaCC 21. They are listed here: [[Deprecated Settings]].